package com.forum.module.blog.dal.mysql.comment;

import com.forum.framework.common.pojo.PageResult;
import com.forum.framework.mybatis.core.mapper.BaseMapperX;
import com.forum.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.forum.module.blog.controller.comment.vo.CommentPageReqVO;
import com.forum.module.blog.dal.dataobject.comment.CommentDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface CommentMapper extends BaseMapperX<CommentDO> {
    default PageResult<CommentDO> selectPage(CommentPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CommentDO>()
                .eqIfPresent(CommentDO::getArticleId, reqVO.getArticleId())
                .eqIfPresent(CommentDO::getUserId, reqVO.getUserId())
                .eqIfPresent(CommentDO::getStatus, reqVO.getStatus())
                .eqIfPresent(CommentDO::getParentId, reqVO.getParentId()));
    }

    @Update("UPDATE forum_robot.blog_comment SET likes = likes + 1 WHERE id = #{id}")
    void incrementLikes(@Param("id") Long id);
}
